using TMPro;
using UnityEngine;
using UnityEngine.UI;

public class UI_PlayerHealthBar : MonoBehaviour
{
    [SerializeField] private Slider slider;
    [SerializeField] private TextMeshProUGUI healthValueInfo;
    private Player_Health playHealth;


    private void OnEnable()
    {
        playHealth = Player.Instance.playerHealth;
        UpdateHealthBar();
        playHealth.OnHealthChange += UpdateHealthBar;
    }
    private void OnDisable()
    {
        playHealth.OnHealthChange -= UpdateHealthBar;
    }
    private void UpdateHealthBar()
    {
        int currentHealth = Mathf.FloorToInt(playHealth.GetCurrentHealth());
        float maxHealth = playHealth.GetMaxHealth();

        slider.value = currentHealth / maxHealth;
        healthValueInfo.text = $"{currentHealth}/{maxHealth}";
    }
}
